home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / kh_gdi.zip / GD_DMWND.CPP < prev    next >
C/C++ Source or Header  |  1996-05-11  |  8KB  |  325 lines

  1. /*  Project gdi_demo
  2.     
  3.     Copyright ⌐ 1995. All Rights Reserved.
  4.  
  5.     SUBSYSTEM:    gdi_demo.exe Application
  6.     FILE:         gd_dmwnd.cpp
  7.     AUTHOR:       S.Vartanov
  8.  
  9.  
  10.     OVERVIEW
  11.     ========
  12.     Source file for implementation of gdi_demoWindow (TWindow).      
  13. */
  14.  
  15.  
  16. #include <owl\owlpch.h>
  17. #pragma hdrstop
  18.  
  19. #include "gd_dmapp.h"
  20.  
  21. #include "gd_dmwnd.h"
  22.  
  23. #include <stdio.h>
  24.  
  25.  
  26. //
  27. // Build a response table for all messages/commands handled
  28. // by the application.
  29. //
  30. DEFINE_RESPONSE_TABLE1(gdi_demoWindow, TWindow)
  31. //{{gdi_demoWindowRSP_TBL_BEGIN}}
  32. //{{gdi_demoWindowRSP_TBL_END}}
  33. END_RESPONSE_TABLE;
  34.  
  35.  
  36. //{{gdi_demoWindow Implementation}}
  37.  
  38.  
  39. //////////////////////////////////////////////////////////
  40. // gdi_demoWindow
  41. // ==========
  42. // Construction/Destruction handling.
  43. gdi_demoWindow::gdi_demoWindow (TWindow* parent, const char far* title, TModule* module)
  44.     : TWindow(parent, title, module)
  45. {
  46.     // INSERT>> Your constructor code here.
  47.  
  48. }
  49.  
  50.  
  51. gdi_demoWindow::~gdi_demoWindow ()
  52. {
  53.     Destroy();
  54.  
  55.     // INSERT>> Your destructor code here.
  56.  
  57. }
  58. #include "kh_gdi\bgipaint.h"
  59.  
  60. class Demo : public KH_Paint
  61.      {
  62.      public:
  63.           void demo();
  64.           void bird();
  65.           void dn(int, int);
  66.           void wing(int, int);
  67.           void pero(int, int, int);
  68.           void calendar(int left, int top, int year, bool visocose);
  69.           int mon(int x, int y, char* mon, int first_day, int num_of_days);
  70.      };
  71. ///////////////////
  72. void Demo::demo()
  73.      {
  74.      set_add_zoom(1,1);          // For all picture
  75.  
  76.      setfillstyle(SOLID_FILL, WHITE);
  77.      set_fill(ON);
  78.      set_zoom(0.1, 0.05);       // To the next "zoom" call
  79.      rectangle(0, 0, 5000, 10000);
  80.  
  81.      set_scroll(800, 500);
  82.      bird();
  83.      set_scroll(0, 500);
  84.      set_zoom(0.35, 0.33);
  85.  
  86.      setcolor(BLACK);
  87.      load("trip.chr");
  88. // Parameters: left, top, year, 0 if not visocose (1980 was)
  89.      calendar(80, 120, 1995, 0);
  90.  
  91.      char s[] = { "  KNOW-HOW.GDI 1.0" };
  92.      load("lcom.chr");
  93.      set_scroll(0, 0);
  94.      set_zoom(1, 1);
  95.      setcolor(GREEN);
  96.      for(int i = 0; i < strlen(s); i++)
  97.           {
  98.           rotate(loc(250, 250), 180 - 180 / strlen(s) * i);
  99.           draw_char(480, 250, s[i], 0);
  100.           }
  101.      rotate(0,0,0);
  102.      }
  103. /////////////////
  104. void Demo::calendar(int l, int t, int year, bool v)
  105.      {
  106.      int day = 7;              // for 1995
  107.      if(year == 1996)          // add cone for other years or use some
  108.     day = 1;              // calculations
  109.      int x = l;
  110.      int y = t + 15;
  111.      for(int i = 1; i <= 3; i++)
  112.     {
  113.     outtextxy(x, y, "Mo");
  114.     y += 30;
  115.     outtextxy(x, y, "Tu");
  116.     y += 30;
  117.           outtextxy(x, y, "We");
  118.           y += 30;
  119.           outtextxy(x, y, "Th");
  120.           y += 30;
  121.           outtextxy(x, y, "Fr");
  122.           y += 30;
  123.           outtextxy(x, y, "Sa");
  124.           y += 30;
  125.           outtextxy(x, y, "Su");
  126.  
  127.           y += 100;
  128.           }
  129.      x = l + 100;
  130.      y = t - 30;
  131.      day = mon(x, y, "January", day, 31);
  132.      int dv = v == 0 ? 28 : 29;
  133.  
  134.      day = mon(x + 340, y, "February", day, dv);
  135.      day = mon(x + 680, y, "March", day, 31);
  136.      day = mon(x + 1020, y, "April", day, 30);
  137.      day = mon(x, y +280, "May", day, 31);
  138.      day = mon(x + 340, y + 280, "June", day, 30);
  139.      day = mon(x + 680, y + 280, "July", day, 31);
  140.      day = mon(x + 1020, y + 280, "August", day, 31);
  141.      day = mon(x, y + 560, "September", day, 30);
  142.      day = mon(x + 340, y + 560, "October", day, 31);
  143.      day = mon(x + 680, y + 560, "November", day, 30);
  144.      day = mon(x + 1020, y + 560, "December", day, 31);
  145.      }
  146. //////////////
  147. int Demo::mon(int x1, int y1, char* head, int start, int num)
  148.      {
  149.      set_fill(ON);
  150.      setfillstyle(SOLID_FILL, WHITE);
  151.      outtextxy(x1 + 60, y1, head);
  152.      int days = 1;
  153.      int ln = start;
  154.      y1 += 15;
  155.  
  156.      char s[10];
  157.      while(1)
  158.           {
  159.           if(days > num)
  160.                 return ln;
  161.           if(ln > 7)
  162.                 {
  163.                 x1 += 50;
  164.                 ln = 1;
  165.                 continue;
  166.                 }
  167.           outtextxy(x1, y1 + 30 * ln, itoa(days, s, 10));
  168.           days++;
  169.     ln++;
  170.           }
  171.      }
  172. ////////////////
  173. void Demo::bird()
  174.      {
  175.      set_zoom(0.1, 0.05);       // To the next "zoom" call
  176.      setlinestyle(1, SOLID_LINE);
  177.      setcolor(BLUE);
  178.      setfillstyle(SOLID_FILL, YELLOW);
  179.  
  180.     int dy = 30;
  181.     for(int i = 1; i <= 12; i++)
  182.           {
  183.         ellipse(1600, 800 + 2 * dy * i, 0, 360, dy * i, dy * i);
  184.         ellipse(1600, 2300 - 2 * dy * i, 0, 360, dy * i, dy * i);
  185.         }
  186.     dn(1800, 1800);
  187.     wing(1900, 1400);
  188.     set_mirror(1600);
  189.     dn(1800, 1800);
  190.      wing(1900, 1400);
  191.      set_mirror(0);
  192.  
  193.     rotate(loc(0, 0), 0);
  194.     ellipse(1600, 700, 0, 360, 360, 360);
  195.     for(i = 0; i <= 60; i++)
  196.     {
  197.         pero(1800, 700, 1);
  198.         rotate(loc(1600, 700), 6 * i);
  199.           }
  200.     rotate(loc(1600, 2000), -90);
  201.     pero(1600, 2000, 7);
  202.     rotate(loc(1600, 2000), -100);
  203.     pero(1600, 2000, 5);
  204.     rotate(loc(1600, 2000), -80);
  205.     pero(1600, 2000, 5);
  206.  
  207.      rotate(loc(0, 0), 0);
  208.  
  209.     ellipse(1700, 600, 0, 360, 60, 130);
  210.     ellipse(1500, 600, 0, 360, 60, 130);
  211.     ellipse(1700, 600, 0, 360, 60, 60);
  212.     ellipse(1500, 600, 0, 360, 60, 60);
  213.     ellipse(1600, 800, 0, 360, 20, 90);
  214.     }
  215. //////////////////
  216. void Demo::wing(int xwin, int ywin)
  217.     {
  218.     for(int i = 0; i <= 10; i++)
  219.         {
  220.         rotate(xwin, ywin, 20 * i - 120);
  221.         pero(xwin, ywin, i / 2);
  222.         }
  223.     set_zoom(0.1, 0.05);
  224.      }
  225. /////////////////
  226. void Demo::dn(int xdn, int ydn)
  227.     {
  228.     rotate(xdn + 40, ydn + 40, -180);
  229.     for(int i = 0; i <= 19; i++)
  230.         {
  231.     rotate(xdn + 40, ydn + 40, 20 * i);
  232.         pero(xdn, ydn, 1);
  233.           }
  234.     }
  235. /////////////////
  236. void Demo::pero(int x, int y, int sz)
  237.     {
  238.     int x1 = x + 40 * sz;
  239.     int x2 = x + 100 * sz;
  240.     int x3 = x + 230 * sz;
  241.      int x4 = x + 300 * sz;
  242.      int y1 = y - 20 * sz;
  243.      int y2 = y - 30 * sz;
  244.      int y3 = y + 20 * sz;
  245.      int y4 = y + 30 * sz;
  246.      int points[] = {  x1, y, x2, y1, x3, y2, x4, y, x3, y4, x2, y3, x1, y };
  247.      fillpoly(7, points);
  248.      line(x, y, x + 300, y);
  249.      }
  250. /////
  251.  
  252. void gdi_demoWindow::Paint (TDC& dc, bool erase, TRect& rect)
  253. {
  254.      TWindow::Paint(dc, erase, rect);
  255.  
  256.      // INSERT>> Your code here.
  257.  
  258.  
  259.      Demo* demo = new Demo();
  260.      demo->DC = dc;
  261.      demo->demo();
  262.      delete demo;
  263.  
  264. /*
  265.      int getx() { POINT p; ::GetCurrentPositionEx(DC, &p); return p.x; }
  266.      int gety() { POINT p; ::GetCurrentPositionEx(DC, &p); return p.y; }
  267.      COLORREF getcolorref() { return color; }
  268.      int getcolor(COLORREF col);
  269.      int getcolor() { return getcolor(color); }
  270.  
  271.      void setcolor(int r, int g, int b)    { color = RGB(r,g,b); }
  272.      void setcolor(int c)
  273.     { color = tricolors[c].colorref; }
  274.  
  275.      void putpixel(int x, int y) { ::SetPixel(DC, x, y, getcolorref()); }
  276.     void setlinestyle(int width, int style)
  277.     { PenSize = width; PenStyle = style; }
  278.     void setlinestyle(int style, unsigned int, int width)
  279.     { PenSize = width; PenStyle = style; }
  280.  
  281.     void setfillstyle(int style, int col)
  282.     {
  283.     pattern_num = style;
  284.     fill_color = col;
  285.     BrushColor = tricolors[col].colorref;
  286.     }
  287.     void setfillstyle(int style, COLORREF col)
  288.     {
  289.     pattern_num = style;
  290.     BrushColor = col;
  291.     }
  292.  
  293.     void moveto(int x, int y) { ::MoveTo(DC, x, y); }
  294.     void lineto(int x, int y);
  295.     void fillpoly(int numpoints, int* polypoints);
  296.     void drawpoly(int numpoints, int far* points);
  297.  
  298. //////////////////////////////////////////////////////////////
  299.         int getx();
  300.         int gety();
  301.     loc get_CP();
  302.     void putpixel(int x, int y);
  303.     void line(int xstart, int ystart, int xend, int yend)
  304.         { moveto(xstart, ystart); lineto(xend, yend); }
  305.  
  306.     void lineto(int x, int y);
  307.     void moveto(int x, int y);
  308.     void circle(int x, int y, int radius)
  309.             { ellipse(x, y, 0, 360, radius, radius); }
  310.     void ellipse(int x, int y, int stangle, int endangle, int xr, int yr);
  311.     void rectangle(int left, int top, int right, int bottom);
  312.     void drawpoly(int numpoints, int far* points);
  313.     void fillpoly(int numpoints, int far* points)
  314.         { int f = fill; fill = ON; drawpoly(numpoints, points);
  315.         fill = f; }
  316.     void bar3d(int l, int t, int r, int b, int d, int top);
  317.     virtual void outtext(char* str, int dir = 0);
  318.     void set_fill(int state) { fill = state; }
  319.  
  320.  
  321. */
  322. }
  323.  
  324.  
  325.